package com.ruoyi.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo.domain.DemoDept;
import com.ruoyi.demo.service.IDemoDeptService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 测试部门Controller
 * 
 * @author ruoyi
 * @date 2023-10-13
 */
@RestController
@RequestMapping("/demo/dept")
public class DemoDeptController extends BaseController
{
    @Autowired
    private IDemoDeptService demoDeptService;

    /**
     * 查询测试部门列表
     */
    @PreAuthorize("@ss.hasPermi('demo:dept:list')")
    @GetMapping("/list")
    public AjaxResult list(DemoDept demoDept)
    {
        List<DemoDept> list = demoDeptService.selectDemoDeptList(demoDept);
        return success(list);
    }

    /**
     * 导出测试部门列表
     */
    @PreAuthorize("@ss.hasPermi('demo:dept:export')")
    @Log(title = "测试部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemoDept demoDept)
    {
        List<DemoDept> list = demoDeptService.selectDemoDeptList(demoDept);
        ExcelUtil<DemoDept> util = new ExcelUtil<DemoDept>(DemoDept.class);
        util.exportExcel(response, list, "测试部门数据");
    }

    /**
     * 获取测试部门详细信息
     */
    @PreAuthorize("@ss.hasPermi('demo:dept:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(demoDeptService.selectDemoDeptById(id));
    }

    /**
     * 新增测试部门
     */
    @PreAuthorize("@ss.hasPermi('demo:dept:add')")
    @Log(title = "测试部门", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DemoDept demoDept)
    {
        return toAjax(demoDeptService.insertDemoDept(demoDept));
    }

    /**
     * 修改测试部门
     */
    @PreAuthorize("@ss.hasPermi('demo:dept:edit')")
    @Log(title = "测试部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DemoDept demoDept)
    {
        return toAjax(demoDeptService.updateDemoDept(demoDept));
    }

    /**
     * 删除测试部门
     */
    @PreAuthorize("@ss.hasPermi('demo:dept:remove')")
    @Log(title = "测试部门", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(demoDeptService.deleteDemoDeptByIds(ids));
    }
}
